home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLMATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  12.6 KB  |  326 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                             /*------------------*
  9.                              *     CPPLMATE.C   *
  10.                              *  Hardware config *
  11.                              *------------------*/
  12.  
  13.  /* Included Files */
  14.  # include <stdio.h>
  15.  # include <io.h>
  16.  # include <dos.h>
  17.  # include <fcntl.h>
  18.  # include <bios.h>
  19.  # include <stdlib.h>
  20.  # include <SYS\stat.h>
  21.  # include <conio.h>
  22.  # include <alloc.h>
  23.  # include <process.h>
  24.  # include <ctype.h>
  25.  # include <string.h>
  26.  
  27.  /* Global Variables */
  28.  extern int x,y,z,i,j,k,l,m,n,bm,xm,ym;
  29.  extern int colour1,colour2,colour3,colour4,colour5,cardtype;
  30.  extern int pfserv,colourchoice,returning,printer;
  31.  extern long dep;
  32.  extern unsigned char c1,trashcan[],work[];
  33.  
  34.  /*-------------------*
  35.   * OPEN WORKING FILE *
  36.   *-------------------*/
  37.   int open_working_file()
  38.     {
  39.       if(pfserv>-1)                    close(pfserv);
  40.       strcpy(trashcan,work);
  41.       if((strlen(trashcan)>3))         strcat(trashcan,"\\SERVICE.FIC");
  42.       else                             strcat(trashcan,"SERVICE.FIC");
  43.       pfserv=open(trashcan,O_RDWR | O_BINARY,S_IREAD|S_IWRITE);
  44.       if(pfserv==-1){
  45.         warning(" Cannot open"," the service file"," for the update","","");
  46.     return(0);
  47.       }
  48.       dep=lseek(pfserv,0L,SEEK_SET);   return(1);
  49.     }
  50.  /*--------------*
  51.   * SAVE COLOURS *
  52.   *--------------*/
  53.   void save_the_colours()
  54.     {
  55.       z=open_working_file();
  56.       if(z==0)                         return;
  57.       /* If the file has been opened we save the colours in it */
  58.       trashcan[3]=0x00;                dep+=4;
  59.       itoa(colour1,trashcan,10);         lseek(pfserv,dep,0);
  60.       write(pfserv,trashcan,3);        dep+=3;
  61.       itoa(colour2,trashcan,10);         lseek(pfserv,dep,0);
  62.       write(pfserv,trashcan,3);        dep+=3;
  63.       itoa(colour3,trashcan,10);         lseek(pfserv,dep,0);
  64.       write(pfserv,trashcan,3);        dep+=3;
  65.       itoa(colour4,trashcan,10);         lseek(pfserv,dep,0);
  66.       write(pfserv,trashcan,3);        dep+=3;
  67.       itoa(colour5,trashcan,10);         lseek(pfserv,dep,0);
  68.       write(pfserv,trashcan,3);
  69.       close(pfserv);                   pfserv=-1;
  70.     }
  71.  /*-------------------*
  72.   * GET SPECIAL COLOR *
  73.   *-------------------*/
  74.   int get_special_colour()
  75.     {
  76.       if(c1==59){
  77.         /* F1 = On-Line help */
  78.     return(59);
  79.       }
  80.       if(c1==72){
  81.         /* Up arrow */
  82.         if(colourchoice>1)                  colourchoice--;
  83.       }
  84.       if(c1==80){
  85.         /* Down arrow */
  86.         if(colourchoice<7)                  colourchoice++;
  87.       }
  88.       if(c1==75){
  89.         /* Left arrow */
  90.         if(colourchoice==7)                 colourchoice--;
  91.       }
  92.       if(c1==77){
  93.         /* Right arrow */
  94.         if(colourchoice==6)                 colourchoice++;
  95.       }
  96.       /* In all the other cases we change nothing         */
  97.       /* But we return the value 0                        */
  98.       /* because arrows need to be confirmed with <Enter> */
  99.       return(0);
  100.     }
  101.  /*------------------*
  102.   * GET COLOUR MOUSE *
  103.   *------------------*/
  104.   int get_colour_mouse()
  105.     {
  106.       if((xm>61)&&(xm<68)){
  107.         /* We are in the 'useful' menu zone */
  108.     if(ym==17)                     return(11);
  109.     if(ym==18)                     return(12);
  110.     if(ym==19)                     return(13);
  111.     if(ym==20)                     return(14);
  112.     if(ym==21)                     return(15);
  113.       }
  114.       if(ym==23){
  115.         /* With the mouse it is choice & confirmation */
  116.     if((xm>61)&&(xm<70))           return(16);
  117.     if((xm>70)&&(xm<80))           return(17);
  118.       }
  119.       /* In all the other cases we return 0  */
  120.       return(0);
  121.     }
  122.  /*----------------------*
  123.   * DISPLAY COLOR CHOICE *
  124.   *----------------------*/
  125.   void display_colour_choice()
  126.     {
  127.       hide_the_mouse();               textattr(colour4);
  128.       gotoxy(62,17);                   cputs("  1   ");
  129.       gotoxy(62,18);                   cputs("  2   ");
  130.       gotoxy(62,19);                   cputs("  3   ");
  131.       gotoxy(62,20);                   cputs("  4   ");
  132.       gotoxy(62,21);                   cputs("  5   ");
  133.       gotoxy(62,23);                   cputs(" Confirm");
  134.       gotoxy(71,23);                   cputs("Esc Quit ");
  135.       /* Outline the current one */
  136.       textattr(colour5);
  137.       if(colourchoice==1){
  138.     gotoxy(62,17);                 cputs("  1   ");
  139.       }
  140.       if(colourchoice==2){
  141.     gotoxy(62,18);                 cputs("  2   ");
  142.       }
  143.       if(colourchoice==3){
  144.     gotoxy(62,19);                 cputs("  3   ");
  145.       }
  146.       if(colourchoice==4){
  147.     gotoxy(62,20);                 cputs("  4   ");
  148.       }
  149.       if(colourchoice==5){
  150.     gotoxy(62,21);                 cputs("  5   ");
  151.       }
  152.       if(colourchoice==6){
  153.         gotoxy(62,23);                 cputs(" Confirm ");
  154.       }
  155.       if(colourchoice==7){
  156.         gotoxy(71,23);                 cputs("Esc Quit ");
  157.       }
  158.       /* And display the colours in the case they had been */
  159.       /* changed during the previous choice                */
  160.       textattr(colour1);
  161.       gotoxy(69,17);                   cputs(" colour1  ");
  162.       textattr(colour2);
  163.       gotoxy(69,18);                   cputs(" colour2  ");
  164.       textattr(colour3);
  165.       gotoxy(69,19);                   cputs(" colour3  ");
  166.       textattr(colour4);
  167.       gotoxy(69,20);                   cputs(" colour4  ");
  168.       textattr(colour5);
  169.       gotoxy(69,21);                   cputs(" colour5  ");
  170.       show_the_mouse();
  171.     }
  172.  /*----------------*
  173.   * PRINTER CHOICE *
  174.   *----------------*/
  175.   void printer_choice()
  176.     {
  177.       returning=open_working_file();
  178.       if(returning==0)                    return;
  179.       save_screen2(35,4);         textattr(colour4);
  180.       hide_the_mouse();               dep+=34;
  181.       /* Get the choice stored in the file */
  182.       lseek(pfserv,dep,0);             read(pfserv,trashcan,1);
  183.       trashcan[1]=0x00;
  184.       gotoxy(37,4);                    cputs("╔══════════════════════╗");
  185.       gotoxy(37,5);                    cputs("║    PRINTER CHOICE    ║");
  186.       gotoxy(37,6);                    cputs("║ Current choice=      ║");
  187.       gotoxy(37,7);                    cputs("╟──────────────────────╢");
  188.       gotoxy(37,8);                    cputs("║ 0 - Non graphics     ║");
  189.       gotoxy(37,9);                    cputs("║ 1 - Epson/IBM graphic║");
  190.       gotoxy(37,10);                   cputs("║ 2 - HP Deskjet ...   ║");
  191.       gotoxy(37,11);                   cputs("║ 3 - HP Laserjet ...  ║");
  192.       gotoxy(37,12);                   cputs("║ 4 - CANON Laser BJ   ║");
  193.       gotoxy(37,13);                   cputs("║ <Esc> No Change      ║");
  194.       gotoxy(37,14);                   cputs("║                      ║");
  195.       gotoxy(37,15);                   cputs("╚══════════════════════╝");
  196.       textattr(colour5);               sound1();
  197.       gotoxy(54,6);                    cputs(trashcan);
  198.       gotoxy(44,14);                   cputs(" Your choice : ");
  199.       show_the_mouse();                returning=wait_for_a_key();
  200.       /* Treat the result */
  201.       if(returning==100){
  202.       /* We clicked */
  203.     if((xm>37)&&(xm<60)){
  204.         /* We are in the 'useful' menu zone */
  205.           if(ym==8)                    returning=0;
  206.           if(ym==9)                    returning=1;
  207.           if(ym==10)                   returning=2;
  208.           if(ym==11)                   returning=3;
  209.           if(ym==12)                   returning=4;
  210.     }
  211.         else                           returning=5;
  212.         /* In all the others case we return = Esc without change */
  213.       }
  214.       if(returning<5){
  215.       /* Store the new choice in the printer variable */
  216.       /* And save it in the service file */
  217.         printer=returning;
  218.         itoa(returning,trashcan,10);       trashcan[1]=0x00;
  219.         lseek(pfserv,dep,0);               write(pfserv,trashcan,1);
  220.     if(pfserv>-1)                          close(pfserv);
  221.     pfserv=-1;
  222.       }
  223.       /* Restore the initial screen and go back to the menu */
  224.       restore_screen2(35,4);           return;
  225.     }
  226.  /*----------------*
  227.   * COLOURS CHOICE *
  228.   *----------------*/
  229.   void colour_choice()
  230.     {
  231.       hide_the_mouse();                save_screen2(55,14);
  232.       colourchoice=1;                  textattr(colour4);
  233.       gotoxy(61,14);                   cputs("╔══════╤═══════════╗");
  234.       gotoxy(61,15);                   cputs("║Choice│  Colours  ║");
  235.       gotoxy(61,16);                   cputs("╟──────┼───────────╢");
  236.       gotoxy(61,17);                   cputs("║  1   │           ║");
  237.       gotoxy(61,18);                   cputs("║  2   │           ║");
  238.       gotoxy(61,19);                   cputs("║  3   │           ║");
  239.       gotoxy(61,20);                   cputs("║  4   │           ║");
  240.       gotoxy(61,21);                   cputs("║  5   │           ║");
  241.       gotoxy(61,22);                   cputs("╠══════╧═╤═════════╣");
  242.       gotoxy(61,23);                   cputs("║ Confirm│Esc Quit ║");
  243.       gotoxy(61,24);                   cputs("╚════════╧═════════╝");
  244.       show_the_mouse();              sound1();
  245.       /* Do nothing until <Esc> is pressed to quit without change */
  246.       /* or <Enter> is pressed to confirm changes */
  247.       while(1){
  248.         /* Do nothing until a key is pressed */
  249.         /* or we pressed a mouse button. */
  250.         display_colour_choice();
  251.     while(1){
  252.       if(kbhit()){
  253.             /* If we pressed a key */
  254.         c1=getch();
  255.         if(c1==0){
  256.               /* Key coded on 2 bytes. Cut the second one. */
  257.           c1=getch();
  258.               returning=get_special_colour();  break;
  259.         }
  260.         else{
  261.           /* We pressed a key */
  262.               returning=get_key();
  263.               if(returning==31)           returning=6;
  264.               if(returning==26)           returning=7;
  265.           break;
  266.         }
  267.       }
  268.           /* Else test the mouse */
  269.           get_mouse_state();
  270.       if(bm==1){
  271.             /* We pressed a mouse button */
  272.             returning=get_colour_mouse();     break;
  273.       }
  274.     }
  275.         /* We treat the result */
  276.         /* Between 1 and 7, we chose a non active line */
  277.         if((returning>0)&&(returning<8))     colourchoice=returning;
  278.         if(returning==40){
  279.         /* We pressed <Enter> */
  280.         /* If it is a colour we change it */
  281.           if((colourchoice>0)&&(colourchoice<6)){
  282.             if((cardtype==1)||(cardtype==3)||(cardtype==4)||(cardtype==5)||(cardtype==9)){
  283.               /* It is a colour card */
  284.               choose_a_colour();
  285.         }
  286.             else                          choose_mono_colour();
  287.             textattr(colour1);            hide_the_mouse();
  288.         window(2,3,59,24);                clrscr();
  289.             window(1,1,80,25);            show_the_mouse();
  290.       }
  291.           if(colourchoice==6){
  292.           /* It is the choice 'save changes' */
  293.             save_the_colours();     break;
  294.       }
  295.     }
  296.         if((returning>10)&&(returning<16)){
  297.         /* Between 11 and 15 we chose a line + action (mouse) */
  298.           colourchoice=returning-10;
  299.           if((cardtype==1)||(cardtype==3)||(cardtype==4)||(cardtype==5)||(cardtype==9)){
  300.             /* It is a colour card */
  301.             choose_a_colour();
  302.       }
  303.           else                         choose_mono_colour();
  304.           textattr(colour1);             hide_the_mouse();
  305.       window(2,3,59,24);           clrscr();
  306.           window(1,1,80,25);           show_the_mouse();
  307.     }
  308.         if(returning==16){
  309.         /* We clicked on the save case */
  310.           save_the_colours();       break;
  311.     }
  312.         /* We pressed <Esc> or <Enter> above Quit */
  313.         /* We want to quit the sub-program without saving */
  314.         if((returning==-1)||((returning==40)&&(colourchoice==7)))   break;
  315.         if(returning==59){
  316.         /* We want a specific help for this sub-menu */
  317.           display_help("CONFIGUR",92,4,1);   restore_help_screen();
  318.     }
  319.       }
  320.       textattr(colour1);               hide_the_mouse();
  321.       window(2,3,59,24);               clrscr();
  322.       window(1,1,80,25);               restore_screen2(55,14);
  323.       show_the_mouse();
  324.     }
  325. /* End of the hardware config file */
  326.